﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
//using System.Xml.Linq;
using System.Collections.Generic;

using YouHP.BLL;
using YouHP.Model;
using YouHP.Utility;

namespace web.admin
{
    public partial class UserActivityCheck : System.Web.UI.Page
    {
        private string URL_BACK = "UserActivity.aspx";
        private UserActivityBLL userActivityBll = UserActivityBLL.Instance;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Bind();
            }
        }

        private void Bind()
        {
            try
            {
                int id = RequestTools.GetQueryInt("id", -1);
                if (id > 0)
                {
                    IList list = new ArrayList();
                    UserActivityInfo info = userActivityBll.GetUserActivityInfo(id);
                    if (info != null)
                    {
                        list.Add(info);
                    }

                    this.userActivityInfo.DataSource = list;
                    this.userActivityInfo.DataBind();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        protected void UpdateButton_click(object sender, EventArgs e)
        {
            try
            {
                UserActivityInfo info = validateForm(this.userActivityInfo);

                if (info != null)
                {
                    info.Id = Convert.ToInt32(this.userActivityInfo.DataKey.Value);
                    if (userActivityBll.CheckUserActivity(info))
                    {
                        HttpContext.Current.Response.Redirect(URL_BACK, true);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        protected void CancelButton_click(object sender, EventArgs e)
        {
            HttpContext.Current.Response.Redirect(URL_BACK, true);
        }

        private UserActivityInfo validateForm(DetailsView formViewCtl)
        {
            UserActivityInfo info = new UserActivityInfo();

            info.Reply = ((TextBox)formViewCtl.FindControl("Reply")).Text;
            info.ReplyDate = DateTime.Now;
            if (Convert.ToInt32(((RadioButtonList)formViewCtl.FindControl("check")).SelectedValue) > 0)
            {
                info.IsVerify = Constants.PASS_ACTIVITY;
            }
            else
            {
                info.IsVerify = Constants.FAIL_ACTIVITY;
            }

            return info;
        }
    }
}

